package common.util;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.PowerManager;

/**
 * 画面のON/OFF処理
 */
public class ScreenOnOffHelper {
    /**
     * 画面をONにする
     * 
     * @param context
     */
    public static final void screenOn(Context context) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock sCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, ScreenOnOffHelper.class.getName());
        sCpuWakeLock.acquire();
        sCpuWakeLock.release();
        sCpuWakeLock = null;
    }

    /**
     * 画面をOFFにする
     * 
     * @param context
     */
    public static final void screenOff(Context context) {
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (devicePolicyManager != null) {
            devicePolicyManager.lockNow();
        }
    }
}
